package cn.wolfcode.trip.base.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;

@Getter
@Setter
@ToString
@JsonIgnoreProperties(value = {"handler"})
public class StrategyComment extends BaseDomain {
    public static final int STATE_MORMAL = 0; // 普通
    public static final int STATE_HOT = 1; // 推荐
    public static final int STATE_DISABLE = -1; // 禁用
    public static final int TYPE_READ = 0; // 已读
    public static final int TYPE_UNREAD= 1; // 未读
    // 评论者
    private User user;
    // 评论的作者
    private User author;
    //发布时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date createTime;
    //点评内容
    private String content;
    //图片
    private String imgUrls;
    //星星数量
    private Integer starNum;
    //所属的攻略
    private Strategy strategy;
    // 评论的状态,是否已读
    private Integer type=TYPE_UNREAD;

    // 回复本条评论的数量
    private Integer commentNums;
    // 点赞本条评论的数量
    private Integer likeNum;
    //上级评论
    private StrategyComment parent;
    // 下集评论的集合
    private List<StrategyComment> childerList;
    // 状态
    private Integer state = STATE_MORMAL;
    // 推荐时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date commendTime;

    // 返回图片的数组
    public String[] getImgArr() {
        if (StringUtils.hasLength(imgUrls)) {
            return imgUrls.split(";");
        }
        return null;
    }
}